package net.zwet.clanworks.resthome.services.user;

import net.zwet.clanworks.common.enumerations.Status;
import net.zwet.clanworks.resthome.GenericService;
import net.zwet.clanworks.resthome.responses.PostResponse;
import org.apache.log4j.Logger;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by zwet on 30-1-14.
 */
@Path("/api/user")
public class AuthenticationService extends GenericService {
    final static Logger log = Logger.getLogger(AuthenticationService.class);

    @POST
    @Path("/login/{userName}/{password}")

    @Produces({
            MediaType.APPLICATION_XML,
            MediaType.APPLICATION_JSON
    })
    public PostResponse authenticate (
            @DefaultValue("unknown") @PathParam("userName") String userName,
            @DefaultValue("unknown") @PathParam("password") String password ) {

        PostResponse response = new PostResponse();

        if (userExists(userName)) {
            response.setResponseCode(Status.OK.getCode());
            response.setResponseText(Status.OK.getDescription());
        }

        return response;
    }

    private boolean userExists(String userName) {
        log.debug("Username: " + userName);
        return true;
    }
}
